package cn.tedu;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

//把所有用户名和昵称查询出来在控制台输出
public class Demo06 {
    public static void main(String[] args) {
        //得到连接对象
        try (Connection conn = DBUtils.getConn();){
            //得到执行SQL语句的对象
            Statement s = conn.createStatement();
            //执行SQL语句
            ResultSet rs = s.executeQuery(
                    "select username,nick from user"
            );
            while (rs.next()){
//                String name = rs.getString("username");
                String name = rs.getString(1);
//                String nick = rs.getString("nick");
                String nick = rs.getString(2);
                System.out.println(name+":"+nick);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
